package com.qf.controller;

import com.qf.pojo.reqVo.UserReq;
import com.qf.pojo.respVo.BaseResp;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/user")
@RestController //responseBody+controller
//@CrossOrigin(allowCredentials = "true",origins = "http://localhost:8081")
public class UserController {

    @Autowired
    UserService userService;
    /**
     * 验证用户的邮箱是否是唯一的
     * @return
     */
    @RequestMapping(value = "/validataEmail",method = RequestMethod.POST)
    public BaseResp validataEmail(@RequestParam("email")String email){
        return userService.validataEmail(email);
    }

    /**
     * 验证用户名是否唯一
     * @param map
     * @return
     */
    @RequestMapping(value = "/validataloginName",method = RequestMethod.POST)
    public BaseResp validataloginName(@RequestBody UserReq userReq){
        return userService.validataloginName(userReq);
    }

    /**
     * 发送验证码
     * @param email
     * @return
     */
    @GetMapping("/getCode")
    public BaseResp getCode(@RequestParam("email")String email){
        return userService.sendMail(email);
    }

    /**
     * 注册
     * @param userReq
     * @return
     */
    @PostMapping("/registry")
    public BaseResp registry(@RequestBody UserReq userReq){
        return userService.registry(userReq);
    }

    /**
     * 登录
     * @param userReq
     * @return
     */
    @PostMapping("/login")
    public BaseResp login(@RequestBody UserReq userReq){
        return userService.login(userReq);
    }

    /**
     * 通过token获取用户的信息
     */
    @PostMapping("/findUserByToken")
    public BaseResp findUserByToken(HttpServletRequest request){
        return userService.findUserByToken(request);
    }
}
